#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char **argv, char **envp) {
	if ( argc != 3) return 1;

	int fromfile = open(argv[1], O_RDONLY);

	// Replaces existing file, or creates it with
	// permissions 644 if nonexistant
	int tofile = open(argv[2], O_CREAT
	                         | O_WRONLY
	                         | O_TRUNC,
	                                    S_IRUSR
	                                  | S_IWUSR
	                                  | S_IRGRP
	                                  | S_IROTH);
	char *buf;
	while (read(fromfile, buf, 1))
		write(tofile, buf, 1);

	close(fromfile);
	close(tofile);

	return 0;
}
